package com.idis.managerApp.controller;

import com.idis.common.base.BaseController;
import com.idis.entity.person;
import com.idis.service.PersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Ming on 2018/1/30.
 */
@RestController
@RequestMapping("/api/admin/person")
@Api(tags = "人员信息接口")
public class PersonController extends BaseController {

    @Autowired
    PersonService personService;

    @ApiOperation("获取所有指导老师信息")
    @GetMapping("/teacher/all")
    public Map findTeacher() {
        return sendDate(personService.findTeacher());
    }

    @ApiOperation("获取所有成员信息")
    @GetMapping("/member/all")
    public Map findMember() {
        return sendDate(personService.findMember());
    }

    @ApiOperation("获取所有人员信息")
    @GetMapping("/all")
    public Map findAll1() {
        return sendDate(personService.findAll());
    }

    @ApiOperation("根据ID查询指导老师")
    @GetMapping("/teacher/{id}")
    public Map findByIdT(@ApiParam("指导老师ID")@PathVariable String id) {
        return sendDate(personService.findById(id));
    }

    @ApiOperation("根据ID查成员")
    @GetMapping("/member/{id}")
    public Map findByIdM(@ApiParam("成员ID")@PathVariable String id) {
        return sendDate(personService.findById(id));
    }

    @PostMapping("/teacher/update")
    @ApiOperation("更新指导老师信息")
    public Map updageTeacher(@ApiParam("指导老师信息")person person) {
        HashMap map = new HashMap();
        if(person.getId().equals("")||person.getName().equals(""))
            sendNull(map);
        addResult(map, String.valueOf(personService.updateTeacher(person)));
        addMessage(map, "修改成功");
        return map;
    }

    @PostMapping("/member/update")
    @ApiOperation("更新成员信息")
    public Map updageMember(@ApiParam("成员信息")person person) {
        HashMap map = new HashMap();
        if(person.getId().equals("")||person.getName().equals("")){
            sendNull(map);
            return map;
        }
        addResult(map, String.valueOf(personService.updateMember(person)));
        addMessage(map, "修改成功");
        return map;
    }

    @ApiOperation("添加新的成员")
    @PostMapping("/member/save")
    public Map saveMember(person person) {
        HashMap map = new HashMap();
        if(person.getName().equals("")){
            sendNull(map);
            return map;
        }
        addResult(map, String.valueOf(personService.saveMember(person)));
        addMessage(map, "保存成功");
        return map;
    }

    @ApiOperation("添加新的老师")
    @PostMapping("/teacher/save")
    public Map saveTeacher(person person) {
        HashMap map = new HashMap();
        if(person.getName().equals("")){
            sendNull(map);
            return map;
        }
        addResult(map, String.valueOf(personService.saveTeacher(person)));
        addMessage(map, "保存成功");
        return map;
    }

    @ApiOperation("根据ID删除人员信息")
    @PostMapping("/delete")
    public Map delete(@ApiParam("人员信息(需要且仅需要ID)")person person) {
        Map map = new HashMap();
        addResult(map, String.valueOf(personService.delete(person)));
        addMessage(map, "删除成功");
        return map;
    }

    @ApiOperation("获取人员类型及其代号")
    @GetMapping("/role")
    public Map getRole() {
        return personService.getRole();
    }



}
